package com.gzw.scm.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.gzw.scm.R;
import com.gzw.scm.bean.JgInfo;
import java.util.ArrayList;
import java.util.List;



/**
 * Created by Administrator on 2017/5/10.
 */

public class QQJGAdapter extends RecyclerView.Adapter{

    public static interface OnRecyclerViewListener {
        void onItemClick(int position);

        boolean onItemLongClick(int position);
    }

    private OnRecyclerViewListener onRecyclerViewListener;

    public void setOnRecyclerViewListener(OnRecyclerViewListener onRecyclerViewListener) {
        this.onRecyclerViewListener = onRecyclerViewListener;
    }

    private List<JgInfo> list = new ArrayList<>();

    public QQJGAdapter(List<JgInfo> list) {
        this.list = list;

    }



    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_qqjg, null);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(lp);
        return new PersonViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int i) {
        final PersonViewHolder holder = (PersonViewHolder) viewHolder;
        holder.position = i;
        holder.tv_jgmc.setText("部门名称:"+"        "+list.get(i).getMc());
        holder.tv_num.setText("申请数量:"+"        "+list.get(i).getNum());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class PersonViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
        public View rootView;
        public TextView tv_jgmc;
        public TextView tv_num;

        public int position;

        public PersonViewHolder(View itemView) {
            super(itemView);
            tv_jgmc = (TextView) itemView.findViewById(R.id.tv_jgmc);
            tv_num = (TextView) itemView.findViewById(R.id.tv_num);

            rootView = itemView.findViewById(R.id.ll);
            rootView.setOnClickListener(this);
            rootView.setOnLongClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (null != onRecyclerViewListener) {
                onRecyclerViewListener.onItemClick(position);
            }
        }

        @Override
        public boolean onLongClick(View v) {
            if (null != onRecyclerViewListener) {
                return onRecyclerViewListener.onItemLongClick(position);
            }
            return false;
        }
    }



}
